Repository navigation
test(api): annotate quota, plugin factory and cleaner tests for strict pyrefly - #45766
Merged
asukaminato0721 merged 6 commits intoNov 8, 2026
Merged
Conversation
…t pyrefly Files: api/tests/unit_tests/core/app/llm/test_quota.py, api/tests/unit_tests/core/plugin/impl/test_model_runtime_factory.py, api/tests/unit_tests/core/rag/cleaner/test_clean_processor.py Added 24 return annotations; dropped 3 pyrefly excludes. Verified: pyrefly 1.4.0 strict single-file check 0 diagnostics, full strict check unchanged, ruff format --check clean.
shi-felix
requested review from
JohnJyong,
QuantumGhost and
WH-2099
as code owners
November 7, 2026 05:51
Contributor
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #45766 +/- ##
=======================================
Coverage 90.01% 90.02%
=======================================
Files 6265 6265
Lines 391789 391831 +42
Branches 78435 78439 +4
=======================================
+ Hits 352679 352731 +52
+ Misses 33020 33011 -9
+ Partials 6090 6089 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…-enabled tests The full-dependency CI strict check reports type diagnostics that already existed in these modules while they were on the exclude list. Mark those exact lines so removing the excludes does not change the diagnostic set. Adds 7 line-level pyrefly suppressions across 2 files. No runtime behaviour changes.
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-11-08 11:18:29.348471226 +0000
+++ /tmp/pyrefly_pr.txt 2026-11-08 11:18:18.024436128 +0000
@@ -3782,16 +3782,6 @@
--> tests/unit_tests/core/app/layers/test_pause_state_persist_layer.py:157:12
ERROR Argument `list[FromClause]` is not assignable to parameter `tables` with type `Sequence[Table] | None` in function `sqlalchemy.sql.schema.MetaData.create_all` [bad-argument-type]
--> tests/unit_tests/core/app/layers/test_trigger_post_layer.py:33:66
-ERROR Object of class `FromClause` has no attribute `insert` [missing-attribute]
- --> tests/unit_tests/core/app/llm/test_quota.py:508:13
-ERROR Object of class `FromClause` has no attribute `insert` [missing-attribute]
- --> tests/unit_tests/core/app/llm/test_quota.py:732:13
-ERROR No matching overload found for function `dict.__init__` called with arguments: (Sequence[Row[tuple[str, int | None]]]) [no-matching-overload]
- --> tests/unit_tests/core/app/llm/test_quota.py:789:32
-ERROR Object of class `FromClause` has no attribute `update` [missing-attribute]
- --> tests/unit_tests/core/app/llm/test_quota.py:800:13
-ERROR Object of class `FromClause` has no attribute `insert` [missing-attribute]
- --> tests/unit_tests/core/app/llm/test_quota.py:846:13
ERROR Argument `Literal[core.app.entities.app_invoke_entities.InvokeFrom.WEB_APP]` is not assignable to parameter `invoke_from` with type `models.enums.InvokeFrom | SQLCoreOperations[models.enums.InvokeFrom | None] | None` in function `models.model.Message.__init__` [bad-argument-type]
--> tests/unit_tests/core/app/task_pipeline/test_based_generate_task_pipeline.py:40:21
ERROR `SimpleNamespace` is not assignable to upper bound `AppGenerateEntity` of type variable `AppGenerateEntityT` [bad-specialization]
@@ -4046,10 +4036,6 @@
--> tests/unit_tests/core/plugin/impl/test_model.py:637:22
ERROR Key `type` is not defined in TypedDict `MultimodalRerankInput` [bad-typed-dict-key]
--> tests/unit_tests/core/plugin/impl/test_model.py:637:23
-ERROR Argument `_FakeModelRuntime` is not assignable to parameter `runtime` with type `ModelRuntime` in function `core.plugin.impl.model_runtime_factory.create_model_type_instance` [bad-argument-type]
- --> tests/unit_tests/core/plugin/impl/test_model_runtime_factory.py:408:17
-ERROR Argument `_FakeModelRuntime` is not assignable to parameter `runtime` with type `ModelRuntime` in function `core.plugin.impl.model_runtime_factory.create_model_type_instance` [bad-argument-type]
- --> tests/unit_tests/core/plugin/impl/test_model_runtime_factory.py:429:21
ERROR No matching overload found for function `typing.MutableMapping.update` called with arguments: (object) [no-matching-overload]
--> tests/unit_tests/core/plugin/impl/test_oauth.py:72:33
ERROR Object of class `NoneType` has no attribute `model` [missing-attribute]
|
asukaminato0721
requested changes
Nov 7, 2026
Replace the bare `# pyrefly: ignore` comments with code-specific suppressions, using the exact error kinds reported by the strict-pyrefly CI check (check-run annotation titles), so each comment silences only the diagnostic it was added for. 7 lines across 2 files: bad-argument-type x2, missing-attribute x4, no-matching-overload x1. No runtime behaviour changes; the strict diagnostic set is unchanged.
Clear five of the seven `# pyrefly: ignore` comments in this module.
`Model.__table__` access: SQLAlchemy never declares `__table__` in its
type layer, so `Provider.__table__.insert()` cannot type-check. The
`insert()` / `update()` constructors accept an ORM entity directly —
their parameter is `_DMLTableArgument`, which includes `Type[Any]` — so
the three inserts and the one update now pass the mapped class itself:
- `insert(TenantCreditPool)` / `insert(Provider)`
- `update(Provider).where(...).values(...)`
Row to dict: `dict(result.all())` tripped `no-matching-overload` because
`Row` is not a `tuple` to the checker. `result.tuples().all()` is the
existing idiom in this repository (three uses in
`tests/unit_tests/services/rbac/test___init__.py`), and dify pins
SQLAlchemy 2.0.49, where `Result.tuples()` is not deprecated.
I ran both forms against a real SQLite engine with SQLAlchemy 2.1.8
before pushing: the insert, the update and the dict conversion all return
the expected rows (`{'a': 13, 'b': 20}`), i.e. same behaviour as before.
The remaining two suppressions in
`core/plugin/impl/test_model_runtime_factory.py` are not touched here:
`create_model_type_instance` takes the aggregated `ModelRuntime`
protocol, whose members are `@abstractmethod`, so `_FakeModelRuntime`
cannot satisfy it without implementing all eleven capabilities.
Verified locally: `python -m py_compile`; `ruff format --check` clean;
`ruff check` error set identical to the PR head baseline.
Replace the Core `insert(Model)` / `update(Model)` statements with ORM entities added to the `sqlite_session` fixture, which is bound to the same SQLite engine as `sqlite_engine`: - `TenantCreditPool(...)` / `Provider(...)` build the rows. `id` is a mapped column declared `init=False`, so the fixed ids are assigned after construction -- the same pattern already used in `commands/test_system.py` and `controllers/console/app/test_message.py`. - The follow-up `update(Provider)` becomes attribute assignment plus a commit. - `quota_type` now passes `models.enums.ProviderQuotaType`, the enum the column is declared with, instead of the differently-typed `core.entities.ProviderQuotaType`. Both members carry the same `"free"` value, so the stored value is unchanged. `_session` is annotated `-> Session` rather than `-> object`; it returns `sessionmaker()`, whose type is known. No behaviour change: the same rows are committed to the same engine before the production code runs. Verified locally: `python -m py_compile`; `ruff format --check` clean; `ruff check` error set identical to the PR head baseline. The tests themselves are exercised by CI (API Unit Tests).
…unking` hit the 20s `pytest-timeout` inside an SSL read on the previous run (1 failed, 13621 passed). It is unrelated to this diff, and a fork PR cannot re-run jobs, so this empty commit re-triggers the workflows.
asukaminato0721
approved these changes
Nov 8, 2026
fatelei
pushed a commit
to fatelei/dify
that referenced
this pull request
Nov 9, 2026
…t pyrefly (langgenius#45766) Co-authored-by: Felix Shi <204130665+shi-felix@users.noreply.github.com>
This was referenced Nov 16, 2026
Open
This was referenced Nov 16, 2026
Merged
Open
This was referenced Nov 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Continue the strict-Pyrefly rollout for the api test suite. This batch brings 3 test
module(s) back under strict checking (part of #24645).
What changed
-> None, or-> objectfor helpers that return avalue) to the test functions in:
api/tests/unit_tests/core/app/llm/test_quota.pyapi/tests/unit_tests/core/plugin/impl/test_model_runtime_factory.pyapi/tests/unit_tests/core/rag/cleaner/test_clean_processor.pyapi/tests/unit_tests/pyrefly.toml.No production code changes and no runtime behaviour changes.
# pyrefly: ignorecomments on the exact lines where CI's strict check(which installs the full dev dependency set) still reports pre-existing diagnostics in
these modules. Those diagnostics were hidden while the files sat on the exclude list;
suppressing them at the reported lines keeps the strict diagnostic set unchanged once
the excludes are removed. No runtime behaviour changes.
Verification
pyrefly check <file> -c pyrefly.toml --summary=none(pyrefly 1.4.0, Python 3.13):0 diagnostics for every file in this batch.
is unchanged from the base-line (0 new diagnostics).
ruff format --checkclean on all touched files.The local interpreter does not have all of dify's third-party packages installed, so
missing-importdiagnostics are environmental and were excluded from the comparison;CI installs the full dev dependency set.
Style Check / Python Style(make type-check-core): strict checks pass with theexcludes removed (follow-up commits address the diagnostics reported on the first run).